﻿using System;
using System.Collections.Generic;
using System.Text;

namespace FDStudio.Core.Entities.Factories
{
    /*
     CreatedOn: 2018-01-25
     CreatedBy: Jackie Lee(天宇遊龍)
     */
    /// <summary>
    /// api请求结果工厂
    /// </summary>
    public class DefaultApiResultFactory : IApiResultFactory
    {
        public IApiResult Create()
        {
            return new ApiResult();
        }

        public IApiResult Falure(int code, string message)
        {
            return Success(ApiResult.ErrorCode, message);
        }

        public IApiResult Success(int code, string message)
        {
            return Create(code, message);
        }

        private IApiResult Create(int code, string message)
        {
            return new ApiResult
            {
                Code = code,
                Message = message
            };
        }

        public IApiResult<T> Success<T>(int code, string message, T result)
        {
            return new ApiResult<T>
            {
                Code = code,
                Message = message,
                Result = result
            };
        }

        public IApiResult<T> Falure<T>(int code, string message)
        {
            return new ApiResult<T>
            {
                Code = code,
                Message = message
            };
        }

        public IApiResult Error(int code, Exception ex)
        {
            return new ApiResult
            {
                Code = code,
                Message = ex.Message
            };
        }

        public IApiResult<T> Error<T>(int code, Exception ex)
        {
            return new ApiResult<T>
            {
                Code = code,
                Message = ex.Message
            };
        }
    }
}
